

<template>
  <div class="resume_header">
    <span>待审核的公司</span>
  </div>
  <div class="resume_center">
    <el-table :data="filterTableData.slice((page - 1) * limit,page*limit)" style="width: 100%" height="400px" size="large">
      <el-table-column label="公司名称"   width="260px" >
          <template #default="scope">
              <router-link :to="{path:'/eInfoPage',query:{eId:scope.row.eId}}">
                {{scope.row.businessName}}
             </router-link>
          </template>
        </el-table-column>
      <el-table-column label="提交人" prop="hrName" width="100px" />
      <el-table-column label="提交时间" prop="confirmTime"  width="220px"/>
      <el-table-column label="审核时间" prop="auditTime" width="220px"/>
      <el-table-column label="审核状态" prop="auditState" width="100px" />
      <el-table-column align="right" min-width="300px" >
        <template #header>
          <el-input v-model="search" size="default" placeholder="搜索" />
        </template>
        <template #default="scope">
          <el-button size="default" type="primary" @click="handleShowJObInfo(scope.$index, scope.row)">查看</el-button>
          <el-button size="default" type="success" :disabled="scope.row.isAudit=='true'?true:false" @click="handleApproved(scope.$index, scope.row)">通过</el-button>
          <el-button size="default" type="danger" :disabled="scope.row.isAudit=='true'?true:false" @click="handleUnqualified(scope.$index, scope.row)">不合格</el-button>
        </template>
      </el-table-column>
    </el-table>
    <AdminAuditResultDialog v-if="dialogFormVisible" 
    :closeAuditResultForm="closeAuditResultForm" 
    :formAuditResultContent="formAuditResultContent" 
    :dialogFormVisible="dialogFormVisible" 
    :handleConfirmAuditResult="handleConfirmAuditResult" 
    :confirmAuditResult="confirmAuditResult"
    />
    <AdminAuditEnterpriseDialog v-if="preAuditEInfoDialog" 
    :closePreAuditEInfoDialog="closePreAuditEInfoDialog" 
    :preAuditEInfoDialog="preAuditEInfoDialog" 

    />

    <div class="pagination">
      <Pagination :page="page" :limit="limit" :handleSizeChange="handleSizeChange" :handleCurrentChange="handleCurrentChange" :filterTableData="filterTableData" :pagesizes="pagesizes" />
    </div>

  </div>
 
</template>
<script lang='ts' setup>
import {adminDelectEnterprise,adminGetAuditEnterprise,adminAuditedEnterprise,adminPreAuditEnterprise} from "@/api/adminApi"
import { computed, ref, onMounted, reactive, watch, onBeforeMount } from 'vue'
import { useStore } from "vuex"
import Pagination from "@/components/Pagination.vue"
import { data,elmessage,formatDate } from "@/hook/hook";
import {useRouter} from "vue-router"
import { ElMessageBox } from 'element-plus'
import AdminAuditResultDialog from "./adminInfo/AdminAuditResultDialog.vue"
import AdminAuditEnterpriseDialog from "@/components/PreAuditEnterpriseDialog.vue"
const store = useStore()
const router=useRouter()

const es=store.state.eState.Es
// 表格数据定义
interface ES {
  auditId:string
  eId:string
  businessName:string
  hrId:string
  hrName:string
  confirmTime:string
  auditTime:string
  auditState:string
  isAudit:string
}
const tableData: ES[] = reactive([])

const search = ref('')
const filterTableData = computed(() =>
  
tableData.filter(
    (data,index) =>
      !search.value ||
      // 通过岗位名称筛选
      data.businessName.toLowerCase().indexOf(search.value.toLowerCase()) !== -1 
  ) 
)


// 分页器
const page = ref(1)
const pagesizes=ref([1,2,3,4,10, 20, 30, 40])
const limit = ref(10)

const handleSizeChange = (val: number) => {
  limit.value=val
  page.value=1
}
const handleCurrentChange = (val: number) => {
  page.value=val
}

// 初始化数据
function initData(){
  if(tableData.length>0){
    tableData.forEach((value,index,self)=>{
      es.forEach((valu:any,inde:any,sel:any)=>{
        if(self.findIndex(item => item.eId==valu.eId) == -1){
          tableData.push(valu)
        }
  })
    })
  }else{
    es.forEach((value:any,index:any,self:any)=>{
    tableData.push(value)
  })
  }

  
}

// 审核结果--dialog
const formAuditResultContent=reactive({
  auditState:"",
  auditId:"",
  auditResultContent:""
})
const dialogFormVisible=ref(false)

// 将审核结果提交
const confirmAuditResult=()=>{
  // 使用循环将表格所操作行的内容更新
  
  const time=formatDate()
  tableData.forEach((value,index,self)=>{
    if(value.auditId==formAuditResultContent.auditId){
      value.auditState=formAuditResultContent.auditState
      value.auditTime=time
      value.isAudit="true"
    }
  })
  const newData={
    ...data(),
    auditState:formAuditResultContent.auditState,
    auditTime:time,
    auditId:formAuditResultContent.auditId,
    auditResultContent:formAuditResultContent.auditResultContent
  }
  
  adminAuditedEnterprise(newData).then((res:any)=>{
    if (res.data["code"] == "200") {
      elmessage(res.data["message"], res.data["type"])
      
    } else if (res.data["code"] == "300") {
      elmessage(res.data["message"], res.data["type"])
      setTimeout(() => {
        router.replace("/login")
      }, 500);
      localStorage.clear()
    } else {
      console.log(res.data);

    }
    closeAuditResultForm()
    formAuditResultContent.auditId=""
    formAuditResultContent.auditResultContent=""
  }
  
  )
}
// 关闭dialog之前的回调,用于用户点击灰色区域触发
const handleConfirmAuditResult=(done:()=>void)=>{
  ElMessageBox.confirm('是否关闭页面，并提交内容？')
    .then(() => {
      done()
      
      confirmAuditResult()
    })
    .catch(() => {
      console.log("取消提交");
      
      // catch error
    })
}

// 关闭对话框的回调
const closeAuditResultForm=()=>{
  dialogFormVisible.value=false
  formAuditResultContent.auditId=""
  formAuditResultContent.auditResultContent=""
}

// 按钮-不通过
const handleUnqualified=(index: number, row: ES)=>{
  formAuditResultContent.auditState="不合格"
  formAuditResultContent.auditId=row.auditId
  dialogFormVisible.value=true
}

// 按钮-通过
const handleApproved=(index: number, row: ES)=>{
  formAuditResultContent.auditState="已通过"
  formAuditResultContent.auditId=row.auditId
  dialogFormVisible.value=true
}

// 查看具体修改的内容
const preAuditEInfoDialog=ref(false)

const e = store.state.adminState.audite
const getPreAuditEnterpriseInfo=(auditId:string)=>{
  const newData = {
        ...data(),
        auditId: auditId
    }
    adminPreAuditEnterprise(newData).then((res: any) => {
        if (res.data["code"] == "200") {
            e.auditId=res.data.datas[0].auditId
            e.eId=res.data.datas[0].eId
            e.eContent=res.data.datas[0].eContent
            e.eSize=res.data.datas[0].eSize
            e.eNature=res.data.datas[0].eNature
            e.eIndustry=res.data.datas[0].eIndustry
            e.eAdvantage=res.data.datas[0].eAdvantage

            e.contactName=res.data.datas[0].contactName
            e.contactPhone=res.data.datas[0].contactPhone
            e.contactEmail=res.data.datas[0].contactEmail
            e.contactAddress=res.data.datas[0].contactAddress

            e.businessName=res.data.datas[0].businessName
            e.businessSetTime=res.data.datas[0].businessSetTime
            e.businessRegCapital=res.data.datas[0].businessRegCapital
            e.businessLegalRepresentative=res.data.datas[0].businessLegalRepresentative
            
            e.hrId=res.data.datas[0].hrId
            e.hrName=res.data.datas[0].hrName
            e.hrEmail=res.data.datas[0].hrEmail
            e.hrPhone=res.data.datas[0].hrPhone

            e.isAudit=res.data.datas[0].isAudit
            e.auditTime=res.data.datas[0].auditTime
            e.confirmTime=res.data.datas[0].confirmTime
            e.auditState=res.data.datas[0].auditState
            e.operationType=res.data.datas[0].operationType
            e.auditResultContent=res.data.datas[0].auditResultContent
            preAuditEInfoDialog.value=true
        } else if (res.data["code"] == "300") {
            elmessage(res.data["message"], res.data["type"])
            setTimeout(() => {
                router.replace("/login")
            }, 500);
            localStorage.clear()
        } else {
            console.log(res.data);

        }

    })
}
const handleShowJObInfo=(index: number, row: ES)=>{
  getPreAuditEnterpriseInfo(row.auditId)
}

const closePreAuditEInfoDialog=()=>{
  preAuditEInfoDialog.value=false
}


const init=()=>{
  adminGetAuditEnterprise(data()).then((res:any)=>{
    if (res.data["code"] == "200") {
      res.data.datas.forEach((value: any, index: any, self: any) => {
        tableData.push({...value})
      })
    } else if (res.data["code"] == "300") {
      elmessage(res.data["message"], res.data["type"])
      setTimeout(() => {
        router.replace("/login")
      }, 500);
      localStorage.clear()
    } else {
      console.log(res.data);
    }
  })
}

onBeforeMount(() => {
  init()
})


</script>
<style scoped>
.pagination{
  float: right;
  margin-right: 50px;
  /* right: 150px; */
}
.resume_center {
  font-family: '微软雅黑';
  height: 800px;
  background-color: #FFF;
}

.resume_header {
  background-color: rgb(215, 215, 215);
  height: 50px;
  display: flex;
  align-items: center;
  padding-left: 20px;
  justify-content: space-between;
}

a {
  text-decoration: none;
  color: #000;
}
</style>